package com.ayou.eggguard.farm.service.impl;

import com.ayou.common.utils.PageBean;
import com.ayou.eggguard.farm.mapper.BlightMapper;
import com.ayou.eggguard.farm.pojo.Blight;
import com.ayou.eggguard.farm.service.BlightService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BlightServiceImpl implements BlightService {
    @Autowired
    private BlightMapper blightMapper;

    @Override
    public PageBean<Blight> getBlights(Integer pageNum, Integer pageSize, String blightName) {
        PageBean<Blight> pb=new PageBean<>();
        PageHelper.startPage(pageNum,pageSize);
        List<Blight> list=blightMapper.getBlights(blightName);
        Page<Blight> p= (Page<Blight>) list;
        pb.setTotal(p.getTotal());
        pb.setItems(p.getResult());
        return pb;
    }

    @Override
    public void add(Blight blight) {
        blightMapper.add(blight);
    }

    @Override
    public void update(Blight blight) {
        blightMapper.update(blight);
    }

    @Override
    public void delete(Integer id) {
        blightMapper.delete(id);
    }

    @Override
    public List<String> getBlightName() {
        return blightMapper.getBlightName();
    }
}
